/*
 * sqldb.h
 *
 *  Created on: 2010-10-27
 *      Author: kaishui
 *
 */

#ifndef SQLDB_H_
#define SQLDB_H_



#define MYDEBUG
#ifdef MYDEBUG
#define DBG(...)  fprintf(stderr, __VA_ARGS__)
#else
#define DBG(...)
#endif


#include "Exception.h"




#define HOST      "192.168.1.168"//"192.168.25.74","localhost"
#define USER      "root"
#define PASSWORD   "@medconn.com"//"kaishui"
#define DBNAME     "AS_armdatabase"


class myDatabase
{
public:
	bool open(string host,string user,string password,string dbname);
	void close();
	bool exec(const string str);
	MYSQL *conn;
};


class myRecordSet
{
public:
	myRecordSet(myDatabase* pDB);
    bool open(const string str);
    bool isEOF();
    void close();

    void moveNext();

    unsigned int getFieldCount();

    bool getFieldValue(unsigned int nIndex, bool& bValue);
    bool getFieldValue(unsigned int nIndex, short int& nValue);
    bool getFieldValue(unsigned int nIndex, unsigned short int &uValue);
    bool getFieldValue(unsigned int nIndex, int& nValue);
    bool getFieldValue(unsigned int nIndex, unsigned int &uValue);
    bool getFieldValue(unsigned int nIndex, long& lValue);
    bool getFieldValue(unsigned int nIndex, unsigned long& ulValue);
    bool getFieldValue(unsigned int nIndex, string& sValue);
    bool getFieldValue(unsigned int nIndex, double& dbValue);

    bool getFieldValue(string fieldName, bool& bValue);
    bool getFieldValue(string fieldName, short int& nValue);
    bool getFieldValue(string fieldName, unsigned short int& uValue);
    bool getFieldValue(string fieldName, int& nValue);
    bool getFieldValue(string fieldName, unsigned int& uValue);
	bool getFieldValue(string fieldName, long& lValue);
	bool getFieldValue(string fieldName, unsigned long& ulValue);
	bool getFieldValue(string fieldName, string& sValue);
	bool getFieldValue(string fieldName, double& dbValue);

private:
    MYSQL *conn;
    MYSQL_RES *result;
    MYSQL_ROW row;
    MYSQL_FIELD *field;

    unsigned int filed_num;

    int getFieldIndex(string fieldName);
};

extern myDatabase *pDB;




#endif /* SQLDB_H_ */
